package revontuli.aMHD.datamanagement;

import java.util.ArrayList;

import revontuli.aMHD.aMHDApp;
import revontuli.aMHD.dataclasses.Departure;

public class DepartureUpdater {
	protected HTTPRetriever httpRetriever = new HTTPRetriever();
	protected XMLParser xmlParser = new XMLParser();
	
	public ArrayList<Departure> update(Integer rev, ArrayList<Integer> lines) {
		StringBuffer sb = new StringBuffer();
		String mLines = lines.toString();
		mLines = mLines.replaceAll("\\[", "");
		mLines = mLines.replaceAll("\\]", "");
		mLines = mLines.replaceAll("\\ ", "");
		
		sb.append(aMHDApp.DATA_SERVER_URL);
		String prefix = aMHDApp.DATA_LINEDEPART_UPDATE_PREFIX;
		prefix = prefix.replaceAll("\\%line", mLines);
		prefix = prefix.replaceAll("\\%rev", Integer.toString(rev));
		sb.append(prefix);
		
		String response = httpRetriever.retrieve(sb.toString());
		return xmlParser.parseDepartureList(response);
	}
}
